const express = require('express');
const cors = require('cors');
const fs = require('fs');
const app = express();
app.use(express.json({ limit: '50mb' }));
app.use(express.urlencoded({ limit: '50mb', extended: true }));
app.use(cors());
app.post('/mock/path', (req, res) => {
  fs.writeFile(`./mock/data/${req.body.path}`, JSON.stringify(req.body.data, null, 2), 'utf8', (err) => {
    if (err) {
      console.log(`${req.body.path}保存数据失败`);
    }
    console.log(`${req.body.path}保存数据成功`);
    res.end(' ');
  });
});

app.listen(3000, () => {
  console.log('运行在3000端口');
});
